var wind = window;
var SendVerify = {};

(function(window) {
    var verifyimg = $(".verifyimg").attr("src");
    $(".reloadverify").click(function () {
        if (verifyimg.indexOf('?') > 0) {
            $(".verifyimg").attr("src", verifyimg + '&random=' + Math.random());
        } else {
            $(".verifyimg").attr("src", verifyimg.replace(/\?.*$/, '') + '?' + Math.random());
        }
    });

	var InterValObj;
    var count = 60;
    var curCount;
    var verifyData = {};
	SendVerify={
	    sendMessage: function (sendCodeBtn,verifyvalue,verifytype,sendtplname) {
	    	SendVerify.resetInterval(sendCodeBtn);
			verifyData['verifyvalue']=verifyvalue;
			verifyData['verifytype']=verifytype;
			verifyData['tplname']=sendtplname;
	        curCount = count;
	        sendCodeBtn.attr("disabled", "true");
	        sendCodeBtn.val("重新发送(" + curCount + ")");
	        InterValObj = window.setInterval(function(){
	        	SendVerify.SetRemainTime(sendCodeBtn);
	        }, 1000);
	        $.ajax({
	            type: "post",
	            dataType: "json",
	            url: sendVerifyCodeUrl,
	            data: verifyData,
	            success: function (data) {
	                console.log(data);
	            }
	        });
	    },
	    resetInterval: function (sendCodeBtn){
	    	wind.clearInterval(InterValObj);
	    	count = 60;
	    	sendCodeBtn.val("获取验证码");
	    },
	    SetRemainTime: function (sendCodeBtn) {
	        if (curCount == 0) {
	            wind.clearInterval(InterValObj);
	            sendCodeBtn.removeAttr("disabled");
	            sendCodeBtn.val("重新发送");
	        }
	        else {
	            curCount--;
	            sendCodeBtn.val("重新发送(" + curCount + ")");
	        }
	    }
    };
})(window);